<?
include 'db_info.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>합주팀 검색 - 트러스 합주시간표</title>
<style type="text/css">
body { color: black; font-size: 10pt; font-family: 맑은고딕, 돋움;}
th { color: white; padding: 10px; font-size: 15pt; font-family: 맑은고딕, 돋움; font-weight: bold; background: #71A7F0;}
td { padding: 5px; }
pre { color: black; font-size: 10pt; font-family: 맑은고딕, 돋움; }
a { color: #FF4848; font-weight: bold; text-decoration:none; }
a.search { color: black; }
a.button { font-weight: normal; font-size: 10pt; }
</style>
<link rel="shortcut icon" href="images/sound.ico" />
<link rel="apple-touch-icon" href="images/sound.png" />
</head>
<body>
<table width="800" align="center">
	<tr><td><a href="index.php">돌아가기</a><hr /></td></tr>
	<tr align="right"><td>
		<form method="get" action="search.php">검색: <input type="text" name="keyword" size="20" maxlength="20" /><input type="submit" value="찾기" /></form>
	</td></tr>
	<tr>
		<td>	
<?
if ($_GET['action'] == 'detail') { // print out the detail of the team
	$teamname = $_GET['teamname'];
	$query_string = "SELECT * FROM team WHERE teamname='$teamname'";
	$query = mysqli_query($connect, $query_string);
	$row = mysqli_fetch_array($query);
	mysqli_free_result($query);

	// name, modify, remove
	echo "<p><span style=\"font-size:20pt; font-weight:bold;\">".$row['teamname']."</span> 팀 상세정보 ";
	echo " [";
	if (!$row['isTemp']) {
		echo "<a class=\"button\" href=\"modify.php?teamname=".$row['teamname']."\">수정</a> / ";
	}
	echo "<a class=\"button\" href=\"remove.php?teamname=".$row['teamname']."\">삭제</a>]</p>\n";
	printout($row);
}
else { // search team containing '$keyword' string
	$keyword = $_GET['keyword'];
	echo "'$keyword' 로 검색한 결과: <br />\n";

	// search from 'team' table containing $keyword string each column
	$query_string = "SELECT * FROM team WHERE 
					(teamname LIKE '%".$keyword."%' 
						or vocal LIKE '%".$keyword."%'
						or first LIKE '%".$keyword."%'
						or second LIKE '%".$keyword."%'
						or bass LIKE '%".$keyword."%'
						or drum LIKE '%".$keyword."%'
						or keyboard LIKE '%".$keyword."%'
						or others LIKE '%".$keyword."%') ORDER BY id DESC";
	$query = mysqli_query($connect, $query_string);
	while ($row = mysqli_fetch_array($query)) {
		echo "<p><span style=\"font-size:20pt; font-weight:bold;\">".$row['teamname']."</span> 팀 상세정보 ";
		echo " [<a class=\"button\" href=\"modify.php?teamname=".$row['teamname']."\">수정</a> / 
		<a class=\"button\" href=\"remove.php?teamname=".$row['teamname']."\">삭제</a>]</p>\n";
		printout($row);
	}
}

function printout($row) {
	// print out information
	if ($row['vocal'] ) echo "보컬: ".$row['vocal']."<br />\n";
	if ($row['first'] ) echo "퍼스트기타: ".$row['first']."<br />\n";
	if ($row['second'] ) echo "세컨드기타: ".$row['second']."<br />\n";
	if ($row['bass'] ) echo "베이스: ".$row['bass']."<br />\n";
	if ($row['drum'] ) echo "드럼: ".$row['drum']."<br />\n";
	if ($row['keyboard'] ) echo "키보드: ".$row['keyboard']."<br />\n";
	if ($row['others'] ) echo "선곡 및 추가입력사항: <br />".nl2br($row['others'])."<br />\n";
}
?>
		</td>
	</tr>
	<tr><td><hr /><a href="index.php">돌아가기</a></td></tr>
</table>
</body>
</html>